﻿using NAnt.SVN.Tasks.Constants;
using NAnt.Core.Attributes;
using NAnt.SVN.Attributes;
using NAnt.Core;
using System;

namespace NAnt.SVN.Tasks
{
    /// <summary>
    /// Superclass of the propset command to auto-ignore common build folders
    /// The folders bin and obj are included, other folders can be specified. If you
    /// specify a value, the default 'bin obj' value is overwritten.
    /// You can run this tasc with the svnautoignore tag in NAnt.
    /// $Id$
    /// </summary>
    [TaskName("svnautoignore")]
    public sealed class AutoIgnore : Task
    {
        #region Private Fields

        private string value = "bin obj";

        #endregion

        #region Public Fields

        /// <summary>
        /// The property value
        /// </summary>
        [TaskAttribute("value", Required = false)]
        [StringValidator()]
        public string Value
        {
            get
            {
                return value;
            }
            set
            {
                this.value = value;
            }
        }

        #endregion

        /// <summary>
        /// Executes the task
        /// </summary>
        protected override void ExecuteTask()
        {
            Ignore i = new Ignore();
            this.CopyTo(i);
            i.Value = "\"" + Value.Replace(" ",Environment.NewLine) + "\"";
            i.Execute();
        }
    }
}
